% figure script for price over coastal line 

%% Local level
ngrid = 20;
xgrid = linspace(0,100,ngrid)';

% ngrid = 400;
% xgrid = linspace(0,200,ngrid)';
% ngrid = 20;
% xgrid = linspace(0,850,ngrid)';

cm = zeros(ngrid,1);
cm_n = zeros(ngrid,1);
for i=2:1:ngrid

cm(i) = median(y(dist2coast>=xgrid(i-1) & dist2coast<xgrid(i)));
cm_n(i) = sum(dist2coast>=xgrid(i-1) & dist2coast<xgrid(i));
end

xgrid(1) = [];
cm(1) = [];
cm_n(1) = [];

figure
subplot(2,1,1)
plot(xgrid, cm,'*-', 'linewidth', 3)
hold on
plot(xgrid, ones(length(xgrid),1)*mean(y), '--', 'linewidth', 3);
set(gca,'linewidth',2,'fontsize', 15);
title('log-price-per-acre over distance from the coast');
subplot(2,1,2)
plot(xgrid, cm_n,'*-', 'linewidth', 3);
set(gca,'linewidth',2,'fontsize', 15);
title('Number of obs. over distance from the coast');

% scatter(dist2coast(dist2coast<5), y(dist2coast<5))

%% Local level
% ngrid = 40;
% xgrid = linspace(0,20,ngrid)';

% ngrid = 400;
% xgrid = linspace(0,200,ngrid)';
ngrid = 20;
xgrid = linspace(0,850,ngrid)';

cm = zeros(ngrid,1);
cm_n = zeros(ngrid,1);
for i=2:1:ngrid

cm(i) = mean(y(dist2coast>=xgrid(i-1) & dist2coast<xgrid(i)));
cm_n(i) = sum(dist2coast>=xgrid(i-1) & dist2coast<xgrid(i));
end

xgrid(1) = [];
cm(1) = [];
cm_n(1) = [];

figure
subplot(2,1,1)
plot(xgrid, cm,'*-', 'linewidth', 3)
hold on
plot(xgrid, ones(length(xgrid),1)*mean(y), '--', 'linewidth', 3);
set(gca,'linewidth',2,'fontsize', 15);
title('log-price-per-acre over distance from the coast');
subplot(2,1,2)
plot(xgrid, cm_n,'*-', 'linewidth', 3);
set(gca,'linewidth',2,'fontsize', 15);
title('Number of obs. over distance from the coast');
